﻿using SAICAPPWEB.BLL;
using SAICAPPWEB.Common;
using SAICAPPWEB.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SAICAPPWEB
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void BtnLogin_Click(object sender, EventArgs e)
        {
            LoginBll login = new LoginBll();
            string name = Request.Form["Name"].ToString().ToLower();
            string pw = Request.Form["Password"].ToString();
            bool islogin = true;
            islogin = login.CheckDomainUser(name, pw);
            if (islogin)
            {
                UserInfo u = new UserInfo();
                UserInfoBll userinfobll = new UserInfoBll();
                UserInfo user = null;
                try
                { user = userinfobll.GetModel(name); }
                catch
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Tips", "<script> alert('该帐号没有登录系统的权限，请联系管理员！'); </script>");
                }
                if (user != null)
                {
                    userinfobll.ImpersonateUser(user.UserAccount);
                    FormsAuthentication.RedirectFromLoginPage(name, false);
                    Response.Redirect("Index.aspx");
                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Tips", "<script> alert('帐号或密码错误！'); </script>");
            }
        }
    }
}